package pers.zff.web.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import pers.zff.web.common.AliyunConstants;
import pers.zff.web.util.FileUtil;
import pers.zff.web.util.HttpUtils;

@Controller
@RequestMapping("/aliyun")
public class AliyunController {

	private static final Log LOG = LogFactory.getLog(AliyunController.class);

//	@Autowired
//	private ALiYunApiService ALiYunApiService;
	
	@ResponseBody
	@RequestMapping(value = "/faceAge", method = RequestMethod.POST, consumes = "multipart/form-data;charset=UTF-8", produces = "application/json;charset=UTF-8")
	public String faceAge(@RequestParam("myfiles") MultipartFile[] files, HttpServletRequest request) {
		
		List<String> filesPaths = FileUtil.filesUpload(files, request);
		String url = AliyunConstants.dancoder_inter_manager_aliyun_faceAge_url;
		String appcode = AliyunConstants.appcode;
		Map<String,Object> paramMap = new HashMap<String,Object>();
		String sendPost = null;
		for (String filePath : filesPaths) {
			paramMap.put("imageData", filePath);
			paramMap.put("appcode", appcode);
			try {
				sendPost = HttpUtils.sendPost(url, paramMap);
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		LOG.info("返回结果是》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》"+sendPost);
		return sendPost;
	}

}
